package com.etime.shycourse.services.salers.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shycourse.services.salers.interfaces.DepartmentServices;
import com.etime.shycourse.dao.DepartmentMapper;
import com.etime.shycourse.pojo.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 销售团队管理 服务实现类
 * </p>
 *
 * @author wb
 * @since 2022-03-24
 */
@Service
public class DepartmentServiceImpl implements DepartmentServices {
    @Autowired
    private DepartmentMapper mapper;

    /**
     * 获取全部可以用的市场部门
     *
     * @return Department list
     * 状态 1
     */
    @Override
    public List<Department> selectAllList() {
        return mapper.selectList (new QueryWrapper<Department> ().eq ("deptstate", 1));
    }

    /**
     * 销售团队管理 分页
     *
     * @param pagenum
     * @param pagesize
     * @return Page<Department>
     */
    @Override
    public Page<Department> selectPage(Long pagenum, Long pagesize) {
        Page<Department> page = null;
        if (pagenum != null && pagesize != null) {
            page = new Page<> (pagenum, pagesize);
        } else {
            page = new Page<> ();
        }
        return mapper.selectPage (page, null);
    }

    @Override
    public Department selectDepartmentById(Integer ID) {
        return mapper.selectById (ID);
    }


    /**
     * 插入一个销售团队
     *
     * @param department
     */
    @Override
    public Integer insertDepartment(Department department) {
        // 部门状态
        department.setDeptstate (1);
        return mapper.insert (department);
    }

    /**
     * 修改一个部门
     *
     * @param department
     */
    @Override
    public Integer updateDepartment(Department department) {
        return mapper.updateById (department);
    }
}
